package com.kitfm.nook.adhoc;

import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class AdHocInstall extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            // Executes the command.
            Runtime.getRuntime().exec("/system/bin/su");
            // Waits for the command to finish.
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        setContentView(R.layout.main);

        setWifiClickListener();
        setInstallClickListener();
        testFileRead();
        checkInstalled();
        
    }
    	private void setInstallClickListener() {
      	 Button installButton = (Button)findViewById(R.id.buttonInstall); 
      	 installButton.setOnClickListener(new View.OnClickListener() {

      		public void onClick(View v) {


      			

      		}
      	}); 
      }
        private void setWifiClickListener() {
          	 Button wifiButton = (Button)findViewById(R.id.siteButton); 
          	 wifiButton.setOnClickListener(new View.OnClickListener() {
          		public void onClick(View v) {
          			//website?
          		}
          		});
          	 }

        
        

		private void testFileRead() {
			boolean installState = (new File("data/data/com.kitfm.nook.adhoc/files/wap")).exists();
			Button testing = (Button)findViewById(R.id.testButton);
			ImageView imageView = (ImageView)findViewById(R.id.nookState);
			Drawable NookState;
		if (installState){
			testing.setText("Found!");
			NookState = getResources().getDrawable(R.drawable.nookhoc);
		} else {
			testing.setText("Negatory.");
			NookState = getResources().getDrawable(R.drawable.nookap);
		}
			imageView.setImageDrawable(NookState);
		}
		private void checkInstalled() {
			boolean installState = (new File("system/bin/adhoc")).exists();
			Button testing = (Button)findViewById(R.id.buttonInstall);
		if (installState){
			testing.setText("AdHoc Script Found!");
			testing.setEnabled(false);
		} else {
			testing.setEnabled(true);
		}}


}
